<!DOCTYPE html>
<html>

<head>
  <meta charset=utf-8>
  <style type="text/css">
    body {
      margin: 0;
    }

    * {
      box-sizing: border-box;
    }

    .row>.column {
      padding: 0 8px;
    }

    .row:after {
      content: "";
      display: table;
      clear: both;
    }

    .column {
      float: left;
      width: 25%;
    }

    .modal {
      display: none;
      position: fixed;
      z-index: 1;
      padding-top: 100px;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      overflow: auto;
      background-color: black;
    }

    .modal-content {
      position: relative;
      background-color: #fefefe;
      margin: auto;
      padding: 0;
      width: 90%;
      max-width: 1200px;
    }

    .close {
      color: white;
      position: absolute;
      top: 10px;
      right: 25px;
      font-size: 35px;
      font-weight: bold;
    }

    .close:hover,
    .close:focus {
      color: #999;
      text-decoration: none;
      cursor: pointer;
    }

    .bigImg {
      display: none;
    }

    .cursor {
      cursor: pointer
    }

    .prev,
    .next {
      cursor: pointer;
      position: absolute;
      top: 50%;
      width: auto;
      padding: 16px;
      margin-top: -50px;
      color: white;
      font-weight: bold;
      font-size: 20px;
      transition: 0.6s ease;
      border-radius: 0 3px 3px 0;
      user-select: none;
      -webkit-user-select: none;
    }

    .next {
      right: 0;
      border-radius: 3px 0 0 3px;
    }

    .prev:hover,
    .next:hover {
      background-color: rgba(0, 0, 0, 0.8);
    }

    img {
      margin-bottom: -4px;
    }

    img.hover-shadow {
      transition: 0.3s
    }

    .hover-shadow:hover {
      box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)
    }
  </style>
</head>

<body>
  <section id="magnifier"></section>

  
  <script >
    var magnifier = {
    init(param) {
      const el = param.el
      const src = param.src
      if (!el || !src) return
      this.createElement(el, src)
      this.initEvent()
    },
    createElement(el, src) {
      const rowDiv = document.createElement('div')
      rowDiv.className = 'row'
      for (let imgSrc of src) {
        const columnDiv = document.createElement('div')
        columnDiv.className = 'column'
        const img = document.createElement('img')
        img.src = imgSrc
        img.style.width = "100%"
        img.className = 'hover-shadow pointer'
        columnDiv.appendChild(img)
        rowDiv.appendChild(columnDiv)
      }
      const modalDiv = document.createElement('div')
      modalDiv.id = 'myModal'
      modalDiv.className = 'modal'
      const span = document.createElement('span')
      span.className = 'close cursor'
      span.innerHTML = '&times;'
      const modalContentDiv = document.createElement('div')
      modalContentDiv.className = 'modal-content'
      modalDiv.appendChild(span)
      modalDiv.appendChild(modalContentDiv)
      for (let imgSrc of src) {
        const slideDiv = document.createElement('div')
        slideDiv.className = 'bigImg'
        const img = document.createElement('img')
        img.src = imgSrc
        img.style.width = "100%"
        slideDiv.appendChild(img)

        modalContentDiv.appendChild(slideDiv)
      }
      const a1 = document.createElement('a')
      a1.className = "prev"
      a1.innerHTML = '&#10094;'
      const a2 = document.createElement('a')
      a2.className = "next"
      a2.innerHTML = '&#10095;'
      modalContentDiv.appendChild(a1)
      modalContentDiv.appendChild(a2)
      el.appendChild(rowDiv)
      el.appendChild(modalDiv)
    },
    initEvent() {
      const imgs = document.querySelectorAll('.hover-shadow')
      const span = document.getElementsByClassName('close')[0]
      const prev = document.getElementsByClassName('prev')[0]
      const next = document.getElementsByClassName('next')[0]
      const myModal = document.getElementById('myModal')

      for (let i = 0; i < imgs.length; i++) {
        imgs[i].onclick = function () {
            myModal.style.display = 'block'
        }
      }

      span.onclick = function () {
        // TODO：通过设置display样式使得大图容器消失
        
      }
      prev.onclick = function () {
        showBigImg(bigImgIndex += 1);
      }
      next.onclick = function () {
        showBigImg(bigImgIndex -= 1);
      }

      let bigImgIndex = 0;
      showBigImg(bigImgIndex);

      function showBigImg(n) {
        const bigImgs = document.getElementsByClassName("bigImg");
        // TODO:图片索引临界值处理
       

        for (let i = 0; i < bigImgs.length; i++) {
          bigImgs[i].style.display = "none";
        }
        // TODO:控制大图显示
        
      }
    }
  }
  magnifier.init({
    // TODO: 请获取id=magnifier的节点
    el: document.querySelector('#magnifier'),
    src: [
      "http://static.runoob.com/images/demo/demo1.jpg",
      "http://static.runoob.com/images/demo/demo2.jpg"
    ]
  })

  </script>
</body>

</html>